{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# COCO Image Viewer\n",
    "This notebook will allow you to view details about a COCO dataset and preview segmentations on annotated images.\n",
    "Learn more about it at: http://cocodataset.org/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-16T08:34:53.909443Z",
     "start_time": "2019-07-16T08:34:53.232749Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\users\\hasee\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\requests\\__init__.py:91: RequestsDependencyWarning: urllib3 (1.25.2) or chardet (3.0.4) doesn't match a supported version!\n",
      "  RequestsDependencyWarning)\n"
     ]
    }
   ],
   "source": [
    "import IPython\n",
    "import os\n",
    "import json\n",
    "import random\n",
    "import numpy as np\n",
    "import requests\n",
    "from io import BytesIO\n",
    "from math import trunc\n",
    "from PIL import Image as PILImage\n",
    "from PIL import ImageDraw as PILImageDraw"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-16T08:34:55.689716Z",
     "start_time": "2019-07-16T08:34:53.911439Z"
    }
   },
   "outputs": [],
   "source": [
    "# Load the dataset json\n",
    "class CocoDataset():\n",
    "    def __init__(self, annotation_path, image_dir):\n",
    "        self.annotation_path = annotation_path\n",
    "        self.image_dir = image_dir\n",
    "        self.colors = ['blue', 'purple', 'red', 'green', 'orange', 'salmon', 'pink', 'gold',\n",
    "                       'orchid', 'slateblue', 'limegreen', 'seagreen', 'darkgreen', 'olive',\n",
    "                       'teal', 'aquamarine', 'steelblue', 'powderblue', 'dodgerblue', 'navy',\n",
    "                       'magenta', 'sienna', 'maroon']\n",
    "\n",
    "        json_file = open(self.annotation_path)\n",
    "        self.coco = json.load(json_file)\n",
    "        json_file.close()\n",
    "\n",
    "        self.process_info()\n",
    "        self.process_licenses()\n",
    "        self.process_categories()\n",
    "        self.process_images()\n",
    "        self.process_segmentations()\n",
    "\n",
    "    def display_info(self):\n",
    "        print('Dataset Info:')\n",
    "        print('=============')\n",
    "        if self.info is None:\n",
    "            return\n",
    "        for key, item in self.info.items():\n",
    "            print('  {}: {}'.format(key, item))\n",
    "\n",
    "        requirements = [['description', str],\n",
    "                        ['url', str],\n",
    "                        ['version', str],\n",
    "                        ['year', int],\n",
    "                        ['contributor', str],\n",
    "                        ['date_created', str]]\n",
    "        for req, req_type in requirements:\n",
    "            if req not in self.info:\n",
    "                print('ERROR: {} is missing'.format(req))\n",
    "            elif type(self.info[req]) != req_type:\n",
    "                print('ERROR: {} should be type {}'.format(req, str(req_type)))\n",
    "        print('')\n",
    "\n",
    "    def display_licenses(self):\n",
    "        print('Licenses:')\n",
    "        print('=========')\n",
    "\n",
    "        if self.licenses is None:\n",
    "            return\n",
    "        requirements = [['id', int],\n",
    "                        ['url', str],\n",
    "                        ['name', str]]\n",
    "        for license in self.licenses:\n",
    "            for key, item in license.items():\n",
    "                print('  {}: {}'.format(key, item))\n",
    "            for req, req_type in requirements:\n",
    "                if req not in license:\n",
    "                    print('ERROR: {} is missing'.format(req))\n",
    "                elif type(license[req]) != req_type:\n",
    "                    print('ERROR: {} should be type {}'.format(\n",
    "                        req, str(req_type)))\n",
    "            print('')\n",
    "        print('')\n",
    "\n",
    "    def display_categories(self):\n",
    "        print('Categories:')\n",
    "        print('=========')\n",
    "        for sc_key, sc_val in self.super_categories.items():\n",
    "            print('  super_category: {}'.format(sc_key))\n",
    "            for cat_id in sc_val:\n",
    "                print('    id {}: {}'.format(\n",
    "                    cat_id, self.categories[cat_id]['name']))\n",
    "            print('')\n",
    "\n",
    "    def display_image(self, image_id, show_polys=True, show_bbox=True, show_crowds=True, use_url=False):\n",
    "        print('Image:')\n",
    "        print('======')\n",
    "        if image_id == 'random':\n",
    "            image_id = random.choice(list(self.images.keys()))\n",
    "\n",
    "        # Print the image info\n",
    "        image = self.images[image_id]\n",
    "        for key, val in image.items():\n",
    "            print('  {}: {}'.format(key, val))\n",
    "\n",
    "        # Open the image\n",
    "        if use_url:\n",
    "            image_path = image['coco_url']\n",
    "            response = requests.get(image_path)\n",
    "            image = PILImage.open(BytesIO(response.content))\n",
    "\n",
    "        else:\n",
    "            image_path = os.path.join(self.image_dir, image['file_name'])\n",
    "            image = PILImage.open(image_path)\n",
    "\n",
    "        # Calculate the size and adjusted display size\n",
    "        max_width = 600\n",
    "        image_width, image_height = image.size\n",
    "        adjusted_width = min(image_width, max_width)\n",
    "        adjusted_ratio = adjusted_width / image_width\n",
    "        adjusted_height = adjusted_ratio * image_height\n",
    "\n",
    "        # Create list of polygons to be drawn\n",
    "        polygons = {}\n",
    "        bbox_polygons = {}\n",
    "        rle_regions = {}\n",
    "        poly_colors = {}\n",
    "        bbox_categories = {}\n",
    "        print('  segmentations ({}):'.format(\n",
    "            len(self.segmentations[image_id])))\n",
    "        for i, segm in enumerate(self.segmentations[image_id]):\n",
    "            polygons_list = []\n",
    "            if segm['iscrowd'] != 0:\n",
    "                # Gotta decode the RLE\n",
    "                px = 0\n",
    "                x, y = 0, 0\n",
    "                rle_list = []\n",
    "                for j, counts in enumerate(segm['segmentation']['counts']):\n",
    "                    if j % 2 == 0:\n",
    "                        # Empty pixels\n",
    "                        px += counts\n",
    "                    else:\n",
    "                        # Need to draw on these pixels, since we are drawing in vector form,\n",
    "                        # we need to draw horizontal lines on the image\n",
    "                        x_start = trunc(\n",
    "                            trunc(px / image_height) * adjusted_ratio)\n",
    "                        y_start = trunc(px % image_height * adjusted_ratio)\n",
    "                        px += counts\n",
    "                        x_end = trunc(trunc(px / image_height)\n",
    "                                      * adjusted_ratio)\n",
    "                        y_end = trunc(px % image_height * adjusted_ratio)\n",
    "                        if x_end == x_start:\n",
    "                            # This is only on one line\n",
    "                            rle_list.append(\n",
    "                                {'x': x_start, 'y': y_start, 'width': 1, 'height': (y_end - y_start)})\n",
    "                        if x_end > x_start:\n",
    "                            # This spans more than one line\n",
    "                            # Insert top line first\n",
    "                            rle_list.append(\n",
    "                                {'x': x_start, 'y': y_start, 'width': 1, 'height': (image_height - y_start)})\n",
    "\n",
    "                            # Insert middle lines if needed\n",
    "                            lines_spanned = x_end - x_start + 1  # total number of lines spanned\n",
    "                            full_lines_to_insert = lines_spanned - 2\n",
    "                            if full_lines_to_insert > 0:\n",
    "                                full_lines_to_insert = trunc(\n",
    "                                    full_lines_to_insert * adjusted_ratio)\n",
    "                                rle_list.append(\n",
    "                                    {'x': (x_start + 1), 'y': 0, 'width': full_lines_to_insert, 'height': image_height})\n",
    "\n",
    "                            # Insert bottom line\n",
    "                            rle_list.append(\n",
    "                                {'x': x_end, 'y': 0, 'width': 1, 'height': y_end})\n",
    "                if len(rle_list) > 0:\n",
    "                    rle_regions[segm['id']] = rle_list\n",
    "            else:\n",
    "                # Add the polygon segmentation\n",
    "                for segmentation_points in segm['segmentation']:\n",
    "                    segmentation_points = np.multiply(\n",
    "                        segmentation_points, adjusted_ratio).astype(int)\n",
    "                    polygons_list.append(\n",
    "                        str(segmentation_points).lstrip('[').rstrip(']'))\n",
    "            polygons[segm['id']] = polygons_list\n",
    "            if i < len(self.colors):\n",
    "                poly_colors[segm['id']] = self.colors[i]\n",
    "            else:\n",
    "                poly_colors[segm['id']] = 'white'\n",
    "\n",
    "            bbox = segm['bbox']\n",
    "            bbox_points = [bbox[0], bbox[1], bbox[0] + bbox[2], bbox[1],\n",
    "                           bbox[0] + bbox[2], bbox[1] +\n",
    "                           bbox[3], bbox[0], bbox[1] + bbox[3],\n",
    "                           bbox[0], bbox[1]]\n",
    "            bbox_points = np.multiply(bbox_points, adjusted_ratio).astype(int)\n",
    "            bbox_polygons[segm['id']] = str(\n",
    "                bbox_points).lstrip('[').rstrip(']')\n",
    "            bbox_categories[segm['id']] = self.categories[segm['category_id']]\n",
    "            # Print details\n",
    "            print('    {}:{}:{}'.format(\n",
    "                segm['id'], poly_colors[segm['id']], self.categories[segm['category_id']]))\n",
    "\n",
    "        # Draw segmentation polygons on image\n",
    "        html = '<div class=\"container\" style=\"position:relative;\">'\n",
    "        html += '<img src=\"{}\" style=\"position:relative;top:0px;left:0px;width:{}px;\">'.format(\n",
    "            image_path, adjusted_width)\n",
    "        html += '<div class=\"svgclass\"><svg width=\"{}\" height=\"{}\">'.format(\n",
    "            adjusted_width, adjusted_height)\n",
    "\n",
    "        if show_polys:\n",
    "            for seg_id, points_list in polygons.items():\n",
    "                fill_color = poly_colors[seg_id]\n",
    "                stroke_color = poly_colors[seg_id]\n",
    "                for points in points_list:\n",
    "                    html += '<polygon points=\"{}\" style=\"fill:{}; stroke:{}; stroke-width:1; fill-opacity:0.5\" />'.format(\n",
    "                        points, fill_color, stroke_color)\n",
    "\n",
    "        if show_crowds:\n",
    "            for seg_id, rect_list in rle_regions.items():\n",
    "                fill_color = poly_colors[seg_id]\n",
    "                stroke_color = poly_colors[seg_id]\n",
    "                for rect_def in rect_list:\n",
    "                    x, y = rect_def['x'], rect_def['y']\n",
    "                    w, h = rect_def['width'], rect_def['height']\n",
    "                    html += '<rect x=\"{}\" y=\"{}\" width=\"{}\" height=\"{}\" style=\"fill:{}; stroke:{}; stroke-width:1; fill-opacity:0.5; stroke-opacity:0.5\" />'.format(\n",
    "                        x, y, w, h, fill_color, stroke_color)\n",
    "\n",
    "        if show_bbox:\n",
    "            for seg_id, points in bbox_polygons.items():\n",
    "                x, y = [int(i) for i in points.split()[:2]]\n",
    "                html += '<text x=\"{}\" y=\"{}\" fill=\"yellow\">{}</text>'.format(\n",
    "                    x, y, bbox_categories[seg_id][\"name\"])\n",
    "                fill_color = poly_colors[seg_id]\n",
    "                stroke_color = poly_colors[seg_id]\n",
    "                html += '<polygon points=\"{}\" style=\"fill:{}; stroke:{}; stroke-width:1; fill-opacity:0\" />'.format(\n",
    "                    points, fill_color, stroke_color)\n",
    "\n",
    "        html += '</svg></div>'\n",
    "        html += '</div>'\n",
    "        html += '<style>'\n",
    "        html += '.svgclass { position:absolute; top:0px; left:0px;}'\n",
    "        html += '</style>'\n",
    "        return html\n",
    "\n",
    "    def process_info(self):\n",
    "        self.info = self.coco.get('info')\n",
    "\n",
    "    def process_licenses(self):\n",
    "        self.licenses = self.coco.get('licenses')\n",
    "\n",
    "    def process_categories(self):\n",
    "        self.categories = {}\n",
    "        self.super_categories = {}\n",
    "        for category in self.coco['categories']:\n",
    "            cat_id = category['id']\n",
    "            super_category = category['supercategory']\n",
    "\n",
    "            # Add category to the categories dict\n",
    "            if cat_id not in self.categories:\n",
    "                self.categories[cat_id] = category\n",
    "            else:\n",
    "                print(\"ERROR: Skipping duplicate category id: {}\".format(category))\n",
    "\n",
    "            # Add category to super_categories dict\n",
    "            if super_category not in self.super_categories:\n",
    "                # Create a new set with the category id\n",
    "                self.super_categories[super_category] = {cat_id}\n",
    "            else:\n",
    "                self.super_categories[super_category] |= {\n",
    "                    cat_id}  # Add category id to the set\n",
    "\n",
    "    def process_images(self):\n",
    "        self.images = {}\n",
    "        for image in self.coco['images']:\n",
    "            image_id = image['id']\n",
    "            if image_id in self.images:\n",
    "                print(\"ERROR: Skipping duplicate image id: {}\".format(image))\n",
    "            else:\n",
    "                self.images[image_id] = image\n",
    "\n",
    "    def process_segmentations(self):\n",
    "        self.segmentations = {}\n",
    "        for segmentation in self.coco['annotations']:\n",
    "            image_id = segmentation['image_id']\n",
    "            if image_id not in self.segmentations:\n",
    "                self.segmentations[image_id] = []\n",
    "            self.segmentations[image_id].append(segmentation)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-16T08:34:55.719664Z",
     "start_time": "2019-07-16T08:34:55.691712Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dataset Info:\n",
      "=============\n",
      "Licenses:\n",
      "=========\n",
      "Categories:\n",
      "=========\n",
      "  super_category: none\n",
      "    id 0: date\n",
      "    id 1: fig\n",
      "    id 2: hazelnut\n",
      "\n"
     ]
    }
   ],
   "source": [
    "annotation_path = './data/coco/output.json'\n",
    "image_dir = './data/VOC/JPEGImages/'\n",
    "\n",
    "coco_dataset = CocoDataset(annotation_path, image_dir)\n",
    "coco_dataset.display_info()\n",
    "coco_dataset.display_licenses()\n",
    "coco_dataset.display_categories()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-16T08:34:55.770499Z",
     "start_time": "2019-07-16T08:34:55.722628Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Image:\n",
      "======\n",
      "  file_name: 0.jpg\n",
      "  id: 0\n",
      "  width: 800\n",
      "  height: 600\n",
      "  segmentations (12):\n",
      "    1:blue:{'supercategory': 'none', 'name': 'date', 'id': 0}\n",
      "    2:purple:{'supercategory': 'none', 'name': 'date', 'id': 0}\n",
      "    3:red:{'supercategory': 'none', 'name': 'date', 'id': 0}\n",
      "    4:green:{'supercategory': 'none', 'name': 'date', 'id': 0}\n",
      "    5:orange:{'supercategory': 'none', 'name': 'date', 'id': 0}\n",
      "    6:salmon:{'supercategory': 'none', 'name': 'hazelnut', 'id': 2}\n",
      "    7:pink:{'supercategory': 'none', 'name': 'hazelnut', 'id': 2}\n",
      "    8:gold:{'supercategory': 'none', 'name': 'hazelnut', 'id': 2}\n",
      "    9:orchid:{'supercategory': 'none', 'name': 'fig', 'id': 1}\n",
      "    10:slateblue:{'supercategory': 'none', 'name': 'fig', 'id': 1}\n",
      "    11:limegreen:{'supercategory': 'none', 'name': 'fig', 'id': 1}\n",
      "    12:seagreen:{'supercategory': 'none', 'name': 'fig', 'id': 1}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div class=\"container\" style=\"position:relative;\"><img src=\"./data/VOC/JPEGImages/0.jpg\" style=\"position:relative;top:0px;left:0px;width:600px;\"><div class=\"svgclass\"><svg width=\"600\" height=\"450.0\"><text x=\"75\" y=\"87\" fill=\"yellow\">date</text><polygon points=\" 75  87 180  87 180 214  75 214  75  87\" style=\"fill:blue; stroke:blue; stroke-width:1; fill-opacity:0\" /><text x=\"240\" y=\"240\" fill=\"yellow\">date</text><polygon points=\"240 240 347 240 347 316 240 316 240 240\" style=\"fill:purple; stroke:purple; stroke-width:1; fill-opacity:0\" /><text x=\"321\" y=\"310\" fill=\"yellow\">date</text><polygon points=\"321 310 439 310 439 395 321 395 321 310\" style=\"fill:red; stroke:red; stroke-width:1; fill-opacity:0\" /><text x=\"448\" y=\"296\" fill=\"yellow\">date</text><polygon points=\"448 296 534 296 534 418 448 418 448 296\" style=\"fill:green; stroke:green; stroke-width:1; fill-opacity:0\" /><text x=\"423\" y=\"195\" fill=\"yellow\">date</text><polygon points=\"423 195 527 195 527 295 423 295 423 195\" style=\"fill:orange; stroke:orange; stroke-width:1; fill-opacity:0\" /><text x=\"183\" y=\"181\" fill=\"yellow\">hazelnut</text><polygon points=\"183 181 237 181 237 235 183 235 183 181\" style=\"fill:salmon; stroke:salmon; stroke-width:1; fill-opacity:0\" /><text x=\"384\" y=\"162\" fill=\"yellow\">hazelnut</text><polygon points=\"384 162 446 162 446 228 384 228 384 162\" style=\"fill:pink; stroke:pink; stroke-width:1; fill-opacity:0\" /><text x=\"64\" y=\"234\" fill=\"yellow\">hazelnut</text><polygon points=\" 64 234 128 234 128 304  64 304  64 234\" style=\"fill:gold; stroke:gold; stroke-width:1; fill-opacity:0\" /><text x=\"275\" y=\"94\" fill=\"yellow\">fig</text><polygon points=\"275  94 405  94 405 174 275 174 275  94\" style=\"fill:orchid; stroke:orchid; stroke-width:1; fill-opacity:0\" /><text x=\"421\" y=\"126\" fill=\"yellow\">fig</text><polygon points=\"421 126 524 126 524 187 421 187 421 126\" style=\"fill:slateblue; stroke:slateblue; stroke-width:1; fill-opacity:0\" /><text x=\"155\" y=\"204\" fill=\"yellow\">fig</text><polygon points=\"155 204 234 204 234 322 155 322 155 204\" style=\"fill:limegreen; stroke:limegreen; stroke-width:1; fill-opacity:0\" /><text x=\"281\" y=\"166\" fill=\"yellow\">fig</text><polygon points=\"281 166 382 166 382 246 281 246 281 166\" style=\"fill:seagreen; stroke:seagreen; stroke-width:1; fill-opacity:0\" /></svg></div></div><style>.svgclass { position:absolute; top:0px; left:0px;}</style>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "html = coco_dataset.display_image(0, use_url=False)\n",
    "IPython.display.HTML(html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-16T08:34:55.787455Z",
     "start_time": "2019-07-16T08:34:55.772497Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Image:\n",
      "======\n",
      "  file_name: 1.jpg\n",
      "  id: 1\n",
      "  width: 800\n",
      "  height: 600\n",
      "  segmentations (9):\n",
      "    13:blue:{'supercategory': 'none', 'name': 'fig', 'id': 1}\n",
      "    14:purple:{'supercategory': 'none', 'name': 'hazelnut', 'id': 2}\n",
      "    15:red:{'supercategory': 'none', 'name': 'hazelnut', 'id': 2}\n",
      "    16:green:{'supercategory': 'none', 'name': 'hazelnut', 'id': 2}\n",
      "    17:orange:{'supercategory': 'none', 'name': 'date', 'id': 0}\n",
      "    18:salmon:{'supercategory': 'none', 'name': 'date', 'id': 0}\n",
      "    19:pink:{'supercategory': 'none', 'name': 'date', 'id': 0}\n",
      "    20:gold:{'supercategory': 'none', 'name': 'date', 'id': 0}\n",
      "    21:orchid:{'supercategory': 'none', 'name': 'date', 'id': 0}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div class=\"container\" style=\"position:relative;\"><img src=\"./data/VOC/JPEGImages/1.jpg\" style=\"position:relative;top:0px;left:0px;width:600px;\"><div class=\"svgclass\"><svg width=\"600\" height=\"450.0\"><text x=\"29\" y=\"92\" fill=\"yellow\">hazelnut</text><polygon points=\" 29  92  85  92  85 160  29 160  29  92\" style=\"fill:green; stroke:green; stroke-width:1; fill-opacity:0\" /><text x=\"336\" y=\"147\" fill=\"yellow\">date</text><polygon points=\"336 147 489 147 489 245 336 245 336 147\" style=\"fill:orange; stroke:orange; stroke-width:1; fill-opacity:0\" /><text x=\"451\" y=\"232\" fill=\"yellow\">date</text><polygon points=\"451 232 582 232 582 380 451 380 451 232\" style=\"fill:salmon; stroke:salmon; stroke-width:1; fill-opacity:0\" /><text x=\"199\" y=\"201\" fill=\"yellow\">date</text><polygon points=\"199 201 332 201 332 345 199 345 199 201\" style=\"fill:pink; stroke:pink; stroke-width:1; fill-opacity:0\" /><text x=\"261\" y=\"306\" fill=\"yellow\">date</text><polygon points=\"261 306 392 306 392 421 261 421 261 306\" style=\"fill:gold; stroke:gold; stroke-width:1; fill-opacity:0\" /><text x=\"73\" y=\"254\" fill=\"yellow\">date</text><polygon points=\" 73 254 189 254 189 387  73 387  73 254\" style=\"fill:orchid; stroke:orchid; stroke-width:1; fill-opacity:0\" /><text x=\"291\" y=\"45\" fill=\"yellow\">fig</text><polygon points=\"291  45 384  45 384 147 291 147 291  45\" style=\"fill:blue; stroke:blue; stroke-width:1; fill-opacity:0\" /><text x=\"198\" y=\"12\" fill=\"yellow\">hazelnut</text><polygon points=\"198  12 264  12 264  73 198  73 198  12\" style=\"fill:purple; stroke:purple; stroke-width:1; fill-opacity:0\" /><text x=\"466\" y=\"72\" fill=\"yellow\">hazelnut</text><polygon points=\"466  72 529  72 529 148 466 148 466  72\" style=\"fill:red; stroke:red; stroke-width:1; fill-opacity:0\" /></svg></div></div><style>.svgclass { position:absolute; top:0px; left:0px;}</style>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "html = coco_dataset.display_image(1, use_url=False)\n",
    "IPython.display.HTML(html)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Sample Annotations JSON\n",
    "Below are the contents of 'sample_annotations.json'."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-16T08:34:55.800419Z",
     "start_time": "2019-07-16T08:34:55.790447Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"annotations\": [{\"area\": 23800, \"ignore\": 0, \"id\": 1, \"bbox\": [100, 116, 140, 170], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 0}, {\"area\": 14484, \"ignore\": 0, \"id\": 2, \"bbox\": [321, 320, 142, 102], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 0}, {\"area\": 17741, \"ignore\": 0, \"id\": 3, \"bbox\": [429, 414, 157, 113], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 0}, {\"area\": 18582, \"ignore\": 0, \"id\": 4, \"bbox\": [598, 395, 114, 163], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 0}, {\"area\": 18492, \"ignore\": 0, \"id\": 5, \"bbox\": [565, 260, 138, 134], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 0}, {\"area\": 5184, \"ignore\": 0, \"id\": 6, \"bbox\": [244, 242, 72, 72], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 0}, {\"area\": 7221, \"ignore\": 0, \"id\": 7, \"bbox\": [512, 217, 83, 87], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 0}, {\"area\": 7990, \"ignore\": 0, \"id\": 8, \"bbox\": [86, 312, 85, 94], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 0}, {\"area\": 18444, \"ignore\": 0, \"id\": 9, \"bbox\": [367, 126, 174, 106], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 0}, {\"area\": 11234, \"ignore\": 0, \"id\": 10, \"bbox\": [562, 168, 137, 82], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 0}, {\"area\": 16642, \"ignore\": 0, \"id\": 11, \"bbox\": [207, 273, 106, 157], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 0}, {\"area\": 14310, \"ignore\": 0, \"id\": 12, \"bbox\": [375, 222, 135, 106], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 0}, {\"area\": 16864, \"ignore\": 0, \"id\": 13, \"bbox\": [389, 60, 124, 136], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 1}, {\"area\": 7134, \"ignore\": 0, \"id\": 14, \"bbox\": [265, 16, 87, 82], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 1}, {\"area\": 8568, \"ignore\": 0, \"id\": 15, \"bbox\": [622, 96, 84, 102], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 1}, {\"area\": 6825, \"ignore\": 0, \"id\": 16, \"bbox\": [39, 123, 75, 91], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 1}, {\"area\": 26724, \"ignore\": 0, \"id\": 17, \"bbox\": [448, 196, 204, 131], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 1}, {\"area\": 34278, \"ignore\": 0, \"id\": 18, \"bbox\": [602, 310, 174, 197], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 1}, {\"area\": 33984, \"ignore\": 0, \"id\": 19, \"bbox\": [266, 268, 177, 192], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 1}, {\"area\": 26796, \"ignore\": 0, \"id\": 20, \"bbox\": [349, 408, 174, 154], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 1}, {\"area\": 27412, \"ignore\": 0, \"id\": 21, \"bbox\": [98, 339, 154, 178], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 1}, {\"area\": 43610, \"ignore\": 0, \"id\": 22, \"bbox\": [450, 181, 245, 178], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 10}, {\"area\": 20916, \"ignore\": 0, \"id\": 23, \"bbox\": [255, 26, 126, 166], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 10}, {\"area\": 30464, \"ignore\": 0, \"id\": 24, \"bbox\": [266, 265, 136, 224], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 10}, {\"area\": 7844, \"ignore\": 0, \"id\": 25, \"bbox\": [207, 192, 106, 74], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 10}, {\"area\": 11742, \"ignore\": 0, \"id\": 26, \"bbox\": [112, 294, 114, 103], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 10}, {\"area\": 9393, \"ignore\": 0, \"id\": 27, \"bbox\": [182, 358, 93, 101], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 10}, {\"area\": 25375, \"ignore\": 0, \"id\": 28, \"bbox\": [563, 207, 145, 175], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 11}, {\"area\": 19425, \"ignore\": 0, \"id\": 29, \"bbox\": [498, 351, 111, 175], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 11}, {\"area\": 19180, \"ignore\": 0, \"id\": 30, \"bbox\": [362, 378, 137, 140], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 11}, {\"area\": 22260, \"ignore\": 0, \"id\": 31, \"bbox\": [128, 357, 159, 140], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 11}, {\"area\": 19964, \"ignore\": 0, \"id\": 32, \"bbox\": [208, 439, 124, 161], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 11}, {\"area\": 12320, \"ignore\": 0, \"id\": 33, \"bbox\": [483, 87, 140, 88], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 11}, {\"area\": 14268, \"ignore\": 0, \"id\": 34, \"bbox\": [231, 2, 123, 116], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 11}, {\"area\": 12445, \"ignore\": 0, \"id\": 35, \"bbox\": [293, 233, 95, 131], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 11}, {\"area\": 15525, \"ignore\": 0, \"id\": 36, \"bbox\": [404, 229, 115, 135], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 11}, {\"area\": 4875, \"ignore\": 0, \"id\": 37, \"bbox\": [184, 91, 65, 75], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 11}, {\"area\": 7569, \"ignore\": 0, \"id\": 38, \"bbox\": [236, 136, 87, 87], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 11}, {\"area\": 8448, \"ignore\": 0, \"id\": 39, \"bbox\": [122, 300, 96, 88], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 11}, {\"area\": 20349, \"ignore\": 0, \"id\": 40, \"bbox\": [124, 204, 119, 171], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 12}, {\"area\": 20790, \"ignore\": 0, \"id\": 41, \"bbox\": [229, 222, 126, 165], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 12}, {\"area\": 21114, \"ignore\": 0, \"id\": 42, \"bbox\": [385, 253, 153, 138], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 12}, {\"area\": 15336, \"ignore\": 0, \"id\": 43, \"bbox\": [416, 445, 108, 142], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 12}, {\"area\": 20538, \"ignore\": 0, \"id\": 44, \"bbox\": [219, 451, 163, 126], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 12}, {\"area\": 16848, \"ignore\": 0, \"id\": 45, \"bbox\": [386, 95, 144, 117], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 12}, {\"area\": 8640, \"ignore\": 0, \"id\": 46, \"bbox\": [639, 115, 90, 96], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 12}, {\"area\": 10625, \"ignore\": 0, \"id\": 47, \"bbox\": [273, 113, 85, 125], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 12}, {\"area\": 12300, \"ignore\": 0, \"id\": 48, \"bbox\": [525, 267, 100, 123], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 12}, {\"area\": 6320, \"ignore\": 0, \"id\": 49, \"bbox\": [263, 58, 80, 79], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 12}, {\"area\": 4899, \"ignore\": 0, \"id\": 50, \"bbox\": [492, 61, 69, 71], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 12}, {\"area\": 5400, \"ignore\": 0, \"id\": 51, \"bbox\": [154, 101, 75, 72], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 12}, {\"area\": 8217, \"ignore\": 0, \"id\": 52, \"bbox\": [50, 377, 99, 83], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 12}, {\"area\": 25944, \"ignore\": 0, \"id\": 53, \"bbox\": [247, 29, 184, 141], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 13}, {\"area\": 23560, \"ignore\": 0, \"id\": 54, \"bbox\": [397, 174, 190, 124], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 13}, {\"area\": 23681, \"ignore\": 0, \"id\": 55, \"bbox\": [39, 127, 199, 119], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 13}, {\"area\": 10672, \"ignore\": 0, \"id\": 56, \"bbox\": [537, 440, 116, 92], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 13}, {\"area\": 6624, \"ignore\": 0, \"id\": 57, \"bbox\": [531, 102, 92, 72], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 13}, {\"area\": 4582, \"ignore\": 0, \"id\": 58, \"bbox\": [470, 314, 79, 58], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 13}, {\"area\": 6882, \"ignore\": 0, \"id\": 59, \"bbox\": [582, 364, 93, 74], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 13}, {\"area\": 7811, \"ignore\": 0, \"id\": 60, \"bbox\": [162, 257, 107, 73], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 13}, {\"area\": 16610, \"ignore\": 0, \"id\": 61, \"bbox\": [316, 123, 110, 151], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 14}, {\"area\": 19608, \"ignore\": 0, \"id\": 62, \"bbox\": [454, 135, 114, 172], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 14}, {\"area\": 19024, \"ignore\": 0, \"id\": 63, \"bbox\": [584, 91, 116, 164], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 14}, {\"area\": 16146, \"ignore\": 0, \"id\": 64, \"bbox\": [519, 336, 117, 138], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 14}, {\"area\": 14986, \"ignore\": 0, \"id\": 65, \"bbox\": [181, 381, 127, 118], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 14}, {\"area\": 16533, \"ignore\": 0, \"id\": 66, \"bbox\": [118, 80, 167, 99], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 14}, {\"area\": 9180, \"ignore\": 0, \"id\": 67, \"bbox\": [112, 323, 108, 85], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 14}, {\"area\": 8360, \"ignore\": 0, \"id\": 68, \"bbox\": [389, 308, 76, 110], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 14}, {\"area\": 4950, \"ignore\": 0, \"id\": 69, \"bbox\": [89, 98, 75, 66], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 14}, {\"area\": 4875, \"ignore\": 0, \"id\": 70, \"bbox\": [84, 241, 65, 75], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 14}, {\"area\": 3894, \"ignore\": 0, \"id\": 71, \"bbox\": [332, 325, 59, 66], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 14}, {\"area\": 6045, \"ignore\": 0, \"id\": 72, \"bbox\": [591, 293, 93, 65], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 14}, {\"area\": 24696, \"ignore\": 0, \"id\": 73, \"bbox\": [122, 152, 168, 147], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 15}, {\"area\": 16761, \"ignore\": 0, \"id\": 74, \"bbox\": [65, 272, 111, 151], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 15}, {\"area\": 18285, \"ignore\": 0, \"id\": 75, \"bbox\": [132, 413, 159, 115], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 15}, {\"area\": 14061, \"ignore\": 0, \"id\": 76, \"bbox\": [349, 58, 129, 109], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 15}, {\"area\": 23870, \"ignore\": 0, \"id\": 77, \"bbox\": [508, 119, 155, 154], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 15}, {\"area\": 7544, \"ignore\": 0, \"id\": 78, \"bbox\": [359, 461, 92, 82], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 15}, {\"area\": 20700, \"ignore\": 0, \"id\": 79, \"bbox\": [144, 197, 115, 180], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 16}, {\"area\": 17934, \"ignore\": 0, \"id\": 80, \"bbox\": [489, 214, 122, 147], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 16}, {\"area\": 15500, \"ignore\": 0, \"id\": 81, \"bbox\": [331, 5, 100, 155], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 17}, {\"area\": 23667, \"ignore\": 0, \"id\": 82, \"bbox\": [268, 340, 147, 161], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 17}, {\"area\": 18480, \"ignore\": 0, \"id\": 83, \"bbox\": [156, 419, 120, 154], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 17}, {\"area\": 26578, \"ignore\": 0, \"id\": 84, \"bbox\": [0, 365, 194, 137], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 17}, {\"area\": 11160, \"ignore\": 0, \"id\": 85, \"bbox\": [176, 193, 120, 93], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 17}, {\"area\": 8448, \"ignore\": 0, \"id\": 86, \"bbox\": [537, 50, 96, 88], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 17}, {\"area\": 7007, \"ignore\": 0, \"id\": 87, \"bbox\": [505, 243, 77, 91], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 17}, {\"area\": 10573, \"ignore\": 0, \"id\": 88, \"bbox\": [427, 285, 97, 109], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 17}, {\"area\": 9212, \"ignore\": 0, \"id\": 89, \"bbox\": [656, 375, 94, 98], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 17}, {\"area\": 8282, \"ignore\": 0, \"id\": 90, \"bbox\": [453, 485, 101, 82], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 17}, {\"area\": 29318, \"ignore\": 0, \"id\": 91, \"bbox\": [233, 72, 214, 137], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 2}, {\"area\": 26703, \"ignore\": 0, \"id\": 92, \"bbox\": [522, 171, 207, 129], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 2}, {\"area\": 23940, \"ignore\": 0, \"id\": 93, \"bbox\": [19, 40, 190, 126], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 2}, {\"area\": 23760, \"ignore\": 0, \"id\": 94, \"bbox\": [256, 317, 132, 180], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 2}, {\"area\": 31212, \"ignore\": 0, \"id\": 95, \"bbox\": [452, 327, 204, 153], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 2}, {\"area\": 16160, \"ignore\": 0, \"id\": 96, \"bbox\": [334, 223, 160, 101], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 2}, {\"area\": 7954, \"ignore\": 0, \"id\": 97, \"bbox\": [492, 50, 97, 82], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 2}, {\"area\": 7560, \"ignore\": 0, \"id\": 98, \"bbox\": [412, 498, 90, 84], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 2}, {\"area\": 24510, \"ignore\": 0, \"id\": 99, \"bbox\": [125, 52, 190, 129], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 3}, {\"area\": 25270, \"ignore\": 0, \"id\": 100, \"bbox\": [285, 60, 133, 190], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 3}, {\"area\": 31302, \"ignore\": 0, \"id\": 101, \"bbox\": [454, 46, 222, 141], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 3}, {\"area\": 26576, \"ignore\": 0, \"id\": 102, \"bbox\": [205, 236, 151, 176], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 3}, {\"area\": 20172, \"ignore\": 0, \"id\": 103, \"bbox\": [53, 321, 164, 123], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 3}, {\"area\": 22794, \"ignore\": 0, \"id\": 104, \"bbox\": [27, 102, 131, 174], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 3}, {\"area\": 31524, \"ignore\": 0, \"id\": 105, \"bbox\": [568, 214, 148, 213], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 3}, {\"area\": 21812, \"ignore\": 0, \"id\": 106, \"bbox\": [328, 384, 133, 164], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 3}, {\"area\": 13431, \"ignore\": 0, \"id\": 107, \"bbox\": [212, 382, 121, 111], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 3}, {\"area\": 9737, \"ignore\": 0, \"id\": 108, \"bbox\": [473, 195, 107, 91], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 3}, {\"area\": 9373, \"ignore\": 0, \"id\": 109, \"bbox\": [404, 314, 103, 91], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 3}, {\"area\": 6450, \"ignore\": 0, \"id\": 110, \"bbox\": [217, 176, 75, 86], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 3}, {\"area\": 25256, \"ignore\": 0, \"id\": 111, \"bbox\": [194, 65, 164, 154], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 4}, {\"area\": 25728, \"ignore\": 0, \"id\": 112, \"bbox\": [470, 245, 201, 128], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 4}, {\"area\": 17278, \"ignore\": 0, \"id\": 113, \"bbox\": [37, 429, 163, 106], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 4}, {\"area\": 18300, \"ignore\": 0, \"id\": 114, \"bbox\": [55, 51, 150, 122], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 4}, {\"area\": 27984, \"ignore\": 0, \"id\": 115, \"bbox\": [467, 26, 212, 132], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 4}, {\"area\": 11438, \"ignore\": 0, \"id\": 116, \"bbox\": [66, 298, 133, 86], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 4}, {\"area\": 8549, \"ignore\": 0, \"id\": 117, \"bbox\": [285, 236, 83, 103], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 4}, {\"area\": 5780, \"ignore\": 0, \"id\": 118, \"bbox\": [354, 367, 85, 68], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 4}, {\"area\": 20989, \"ignore\": 0, \"id\": 119, \"bbox\": [105, 90, 151, 139], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 5}, {\"area\": 18612, \"ignore\": 0, \"id\": 120, \"bbox\": [314, 191, 132, 141], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 5}, {\"area\": 21353, \"ignore\": 0, \"id\": 121, \"bbox\": [445, 334, 163, 131], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 5}, {\"area\": 19030, \"ignore\": 0, \"id\": 122, \"bbox\": [258, 339, 173, 110], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 5}, {\"area\": 18444, \"ignore\": 0, \"id\": 123, \"bbox\": [331, 436, 174, 106], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 5}, {\"area\": 16377, \"ignore\": 0, \"id\": 124, \"bbox\": [11, 321, 159, 103], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 5}, {\"area\": 11021, \"ignore\": 0, \"id\": 125, \"bbox\": [606, 254, 103, 107], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 5}, {\"area\": 10368, \"ignore\": 0, \"id\": 126, \"bbox\": [244, 439, 108, 96], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 5}, {\"area\": 7360, \"ignore\": 0, \"id\": 127, \"bbox\": [460, 193, 92, 80], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 5}, {\"area\": 4550, \"ignore\": 0, \"id\": 128, \"bbox\": [548, 69, 70, 65], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 5}, {\"area\": 6435, \"ignore\": 0, \"id\": 129, \"bbox\": [637, 78, 99, 65], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 5}, {\"area\": 3990, \"ignore\": 0, \"id\": 130, \"bbox\": [186, 377, 70, 57], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 5}, {\"area\": 38586, \"ignore\": 0, \"id\": 131, \"bbox\": [285, 247, 218, 177], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 6}, {\"area\": 30888, \"ignore\": 0, \"id\": 132, \"bbox\": [27, 291, 216, 143], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 6}, {\"area\": 31752, \"ignore\": 0, \"id\": 133, \"bbox\": [496, 239, 147, 216], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 6}, {\"area\": 6887, \"ignore\": 0, \"id\": 134, \"bbox\": [338, 115, 71, 97], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 6}, {\"area\": 12096, \"ignore\": 0, \"id\": 135, \"bbox\": [114, 140, 112, 108], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 6}, {\"area\": 10680, \"ignore\": 0, \"id\": 136, \"bbox\": [586, 331, 120, 89], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 6}, {\"area\": 21717, \"ignore\": 0, \"id\": 137, \"bbox\": [173, 47, 127, 171], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 7}, {\"area\": 25885, \"ignore\": 0, \"id\": 138, \"bbox\": [451, 298, 167, 155], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 7}, {\"area\": 16120, \"ignore\": 0, \"id\": 139, \"bbox\": [55, 372, 155, 104], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 7}, {\"area\": 19170, \"ignore\": 0, \"id\": 140, \"bbox\": [17, 19, 142, 135], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 7}, {\"area\": 25284, \"ignore\": 0, \"id\": 141, \"bbox\": [493, 235, 196, 129], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 7}, {\"area\": 11172, \"ignore\": 0, \"id\": 142, \"bbox\": [98, 256, 133, 84], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 7}, {\"area\": 4810, \"ignore\": 0, \"id\": 143, \"bbox\": [207, 260, 74, 65], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 7}, {\"area\": 7040, \"ignore\": 0, \"id\": 144, \"bbox\": [157, 324, 88, 80], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 7}, {\"area\": 16113, \"ignore\": 0, \"id\": 145, \"bbox\": [406, 160, 123, 131], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 8}, {\"area\": 20511, \"ignore\": 0, \"id\": 146, \"bbox\": [490, 217, 159, 129], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 8}, {\"area\": 16884, \"ignore\": 0, \"id\": 147, \"bbox\": [656, 243, 134, 126], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 8}, {\"area\": 17334, \"ignore\": 0, \"id\": 148, \"bbox\": [48, 266, 162, 107], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 8}, {\"area\": 16245, \"ignore\": 0, \"id\": 149, \"bbox\": [232, 263, 171, 95], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 8}, {\"area\": 18666, \"ignore\": 0, \"id\": 150, \"bbox\": [250, 406, 122, 153], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 8}, {\"area\": 10250, \"ignore\": 0, \"id\": 151, \"bbox\": [244, 91, 82, 125], \"category_id\": 1, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 8}, {\"area\": 5775, \"ignore\": 0, \"id\": 152, \"bbox\": [399, 319, 77, 75], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 8}, {\"area\": 4779, \"ignore\": 0, \"id\": 153, \"bbox\": [378, 486, 81, 59], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 8}, {\"area\": 24130, \"ignore\": 0, \"id\": 154, \"bbox\": [211, 52, 190, 127], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 9}, {\"area\": 20400, \"ignore\": 0, \"id\": 155, \"bbox\": [330, 198, 120, 170], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 9}, {\"area\": 27440, \"ignore\": 0, \"id\": 156, \"bbox\": [471, 217, 140, 196], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 9}, {\"area\": 26416, \"ignore\": 0, \"id\": 157, \"bbox\": [476, 440, 208, 127], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 9}, {\"area\": 28888, \"ignore\": 0, \"id\": 158, \"bbox\": [315, 369, 157, 184], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 9}, {\"area\": 20306, \"ignore\": 0, \"id\": 159, \"bbox\": [221, 335, 142, 143], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 9}, {\"area\": 20770, \"ignore\": 0, \"id\": 160, \"bbox\": [129, 234, 134, 155], \"category_id\": 0, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 9}, {\"area\": 6424, \"ignore\": 0, \"id\": 161, \"bbox\": [406, 34, 88, 73], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 9}, {\"area\": 7524, \"ignore\": 0, \"id\": 162, \"bbox\": [601, 351, 76, 99], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 9}, {\"area\": 8484, \"ignore\": 0, \"id\": 163, \"bbox\": [130, 440, 101, 84], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 9}, {\"area\": 5698, \"ignore\": 0, \"id\": 164, \"bbox\": [71, 304, 74, 77], \"category_id\": 2, \"segmentation\": [], \"iscrowd\": 0, \"image_id\": 9}], \"images\": [{\"height\": 600, \"file_name\": \"0.jpg\", \"width\": 800, \"id\": 0}, {\"height\": 600, \"file_name\": \"1.jpg\", \"width\": 800, \"id\": 1}, {\"height\": 600, \"file_name\": \"10.jpg\", \"width\": 800, \"id\": 10}, {\"height\": 600, \"file_name\": \"11.jpg\", \"width\": 800, \"id\": 11}, {\"height\": 600, \"file_name\": \"12.jpg\", \"width\": 800, \"id\": 12}, {\"height\": 600, \"file_name\": \"13.jpg\", \"width\": 800, \"id\": 13}, {\"height\": 600, \"file_name\": \"14.jpg\", \"width\": 800, \"id\": 14}, {\"height\": 600, \"file_name\": \"15.jpg\", \"width\": 800, \"id\": 15}, {\"height\": 600, \"file_name\": \"16.jpg\", \"width\": 800, \"id\": 16}, {\"height\": 600, \"file_name\": \"17.jpg\", \"width\": 800, \"id\": 17}, {\"height\": 600, \"file_name\": \"2.jpg\", \"width\": 800, \"id\": 2}, {\"height\": 600, \"file_name\": \"3.jpg\", \"width\": 800, \"id\": 3}, {\"height\": 600, \"file_name\": \"4.jpg\", \"width\": 800, \"id\": 4}, {\"height\": 600, \"file_name\": \"5.jpg\", \"width\": 800, \"id\": 5}, {\"height\": 600, \"file_name\": \"6.jpg\", \"width\": 800, \"id\": 6}, {\"height\": 600, \"file_name\": \"7.jpg\", \"width\": 800, \"id\": 7}, {\"height\": 600, \"file_name\": \"8.jpg\", \"width\": 800, \"id\": 8}, {\"height\": 600, \"file_name\": \"9.jpg\", \"width\": 800, \"id\": 9}], \"type\": \"instances\", \"categories\": [{\"name\": \"fig\", \"supercategory\": \"none\", \"id\": 1}, {\"name\": \"hazelnut\", \"supercategory\": \"none\", \"id\": 2}, {\"name\": \"date\", \"supercategory\": \"none\", \"id\": 0}]}\n"
     ]
    }
   ],
   "source": [
    "with open(annotation_path) as json_file:\n",
    "    lines = json_file.readlines()\n",
    "for line in lines:\n",
    "    print(line)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-16T09:49:36.227808Z",
     "start_time": "2019-07-16T09:49:36.218807Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Image:\n",
      "======\n",
      "  file_name: 16.jpg\n",
      "  id: 16\n",
      "  width: 800\n",
      "  height: 600\n",
      "  segmentations (2):\n",
      "    79:blue:{'supercategory': 'none', 'name': 'date', 'id': 0}\n",
      "    80:purple:{'supercategory': 'none', 'name': 'date', 'id': 0}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div class=\"container\" style=\"position:relative;\"><img src=\"./data/VOC/JPEGImages/16.jpg\" style=\"position:relative;top:0px;left:0px;width:600px;\"><div class=\"svgclass\"><svg width=\"600\" height=\"450.0\"><text x=\"366\" y=\"160\" fill=\"yellow\">date</text><polygon points=\"366 160 458 160 458 270 366 270 366 160\" style=\"fill:purple; stroke:purple; stroke-width:1; fill-opacity:0\" /><text x=\"108\" y=\"147\" fill=\"yellow\">date</text><polygon points=\"108 147 194 147 194 282 108 282 108 147\" style=\"fill:blue; stroke:blue; stroke-width:1; fill-opacity:0\" /></svg></div></div><style>.svgclass { position:absolute; top:0px; left:0px;}</style>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "html = coco_dataset.display_image(16, use_url=False)\n",
    "IPython.display.HTML(html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
